import urllib.request
import urllib.parse
import json

url = 'https://img3.doubanio.com/view/celebrity/m/public/p1555672594.77.webp'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0'
}


# psot 的请求参数 是不会拼接在url的后面，需要放在请求对象的定制参数当中 post的请求参数必须进行编码，类型
request = urllib.request.Request(url=url, headers=headers)

response = urllib.request.urlopen(request)

context = urllib.read.decode('utf-8')

# obj = json.loads(context)
#
# fp = open('douban,json', 'w', encoding='utf-8')
# fp.write(context)

with open('douban1.json', 'w', encoding='utf-8') as fp:
    fp.write(context)
